package com.framework.servlet;

import org.apache.catalina.ContainerServlet;
import org.apache.catalina.Wrapper;

import javax.servlet.*;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author LIN
 * @date 2022-09-11 20:40
 */
public class DemoServlet implements ContainerServlet, Servlet {
    private Wrapper wrapper;


    @Override
    public Wrapper getWrapper() {
        return this.wrapper;
    }

    @Override
    public void setWrapper(Wrapper wrapper) {
        this.wrapper = wrapper;
    }

    @Override
    public void init(ServletConfig config) throws ServletException {
        System.out.println("init demoServlet");
    }

    @Override
    public ServletConfig getServletConfig() {
        return null;
    }

    @Override
    public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
        System.out.println("service demoServlet");
        HttpServletResponse h = (HttpServletResponse) res;
        ServletOutputStream outputStream = h.getOutputStream();
        outputStream.write("hello world".getBytes());
        outputStream.close();
    }

    @Override
    public String getServletInfo() {
        return null;
    }

    @Override
    public void destroy() {
        System.out.println("destroy demoServlet");
    }
}
